package com.luping.xiao.xiao.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.luping.xiao.xiao.dao.AccPassengerflowHourDao;
import com.luping.xiao.xiao.domain.AccPassengerflowHour;
import com.luping.xiao.xiao.service.AccPassengerflowHourService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccPassengerflowHourServiceImpl extends ServiceImpl<AccPassengerflowHourDao, AccPassengerflowHour> implements AccPassengerflowHourService {

    protected static final Logger log = LoggerFactory.getLogger(OpDispatchGpskmServiceImpl.class);
    @Autowired
    private AccPassengerflowHourDao accPassengerflowHourDao;

    @Override
    public void insertList(List<AccPassengerflowHour> list) {
        log.info("listSize=" + list.size());
        insertBa(list);
    }

    public void insertBa(List<AccPassengerflowHour> list) {
        int insertLength = list.size();
        int i = 0;
        while (insertLength > 1000) {
            saveBatch(list.subList(i, i + 1000));
            i = i + 1000;
            insertLength = insertLength - 1000;
        }
        if (insertLength > 0) {
            saveBatch(list.subList(i, i + insertLength));
        }
        log.info("insertBa");
    }

    public void saveBatch(List<AccPassengerflowHour> list) {
        try {
            accPassengerflowHourDao.saveBatch(list);
        }catch (Exception e){
            for(AccPassengerflowHour l:list){
                log.info("失败数据："+l.toString());
            }
            e.printStackTrace();
        }

    }
}
